home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Argus TE 2.0 / Argus Libraries 2.0 / Argus Standards / ArgusHelp.cp < prev    next >
Encoding:
Text File  |  1995-06-28  |  11.8 KB  |  387 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  
  3.     ArgusHelp.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     This library provides a simple function call to display a dialog
  9.     which displays some help or general information about the
  10.     application.  Reads text from TEXT resource ID identified by
  11.     HELP_TEXT.
  12.  
  13.     Functions Include:
  14.  
  15.       MyHelpDialog            Standard Argus Help Dialog
  16.       
  17.       // Semi-private
  18.       MyHelpEventFilter
  19.       SetUpHelpTEWindow
  20.       MyHelpDoContent
  21.       FnTE_AdjustText
  22.       FnTE_SetToCursorPos
  23.       FnTE_ScrollProc
  24. */
  25.  
  26.  
  27. /********** Includes */
  28. #include <Dialogs.h>
  29. #include "Fn_Prototypes.h"
  30.  
  31. // #include "SampleWindow.h"  // may need to modify
  32. #include "TE Window.h"  // added
  33.  
  34.  
  35. /********** Defines */
  36. #define HELP_DLOG      598
  37. #define HELP_TEXT      598
  38. #define NIL_PTR        0L
  39. #define ALLOCATE_MEM   0
  40. #define IN_FRONT       (WindowPtr)-1L
  41. #define OK_BUTTON      1
  42. #define PR_BUTTON      2
  43. #define SV_BUTTON      3
  44. #define RETURN_KEY     13
  45. #define ENTER_KEY      3
  46. #define VISUAL_DELAY   8  // standard is 8 ticks
  47.  
  48.  
  49. TEHandle             te = 0L;
  50. ControlHandle        vScroll = 0L;
  51. extern TEHandle      *tempTEHptr;
  52. extern ControlHandle *tempVScrollptr;
  53. Str255               okButtonStr;
  54. Str255               printButtonStr;
  55. Str255               saveButtonStr;
  56.  
  57.  
  58. /********** Prototypes */
  59. Boolean        MyHelpDialog( void );
  60. pascal Boolean MyHelpEventFilter(  DialogPtr     theDialog,
  61.                                    EventRecord   *theEvent,
  62.                                    short         *itemHit );
  63. Boolean        SetUpHelpTEWindow(  WindowPtr     w,
  64.                                    Boolean       hasGrowIcon,
  65.                                    Boolean       wordWrap,
  66.                                    short         font,
  67.                                    short         textSize,
  68.                                    short         textInsetPixels,
  69.                                    // results //
  70.                                    TEHandle      *te,
  71.                                    ControlHandle *vScroll );
  72. void           MyHelpDoContent(    WindowPtr     w, 
  73.                                    EventRecord   *e,
  74.                                    TEHandle      *te,
  75.                                    ControlHandle *vScroll,
  76.                                    short         *itemHit );
  77. extern void    FnTE_AdjustText(    TEHandle      *te, 
  78.                                    ControlHandle *vScroll );
  79. extern void    FnTE_SetToCursorPos(TEHandle      *te,
  80.                                    ControlHandle *vScroll );
  81. extern pascal void FnTE_ScrollProc(ControlHandle theControl,
  82.                                    short         theCode );
  83.  
  84.  
  85. /********** MyHelpDialog */
  86.  
  87. Boolean MyHelpDialog( void )
  88. {
  89.     WindowPtr     docWindow;
  90.     DialogPtr     dialog;
  91.     Boolean       done;
  92.     Boolean       result;
  93.     short         itemHit;
  94.     short         itemType;
  95.     Handle        itemHandle;
  96.     Rect          itemRect;
  97.     EventRecord   theEvent;
  98.     long          finalTicks;
  99.     THPrint       pPrintH;
  100.     short         vRef;
  101.     short         refNum;
  102.  
  103.     result = FALSE;
  104.     pPrintH = (TPrint **)NewHandle( sizeof( TPrint ) );
  105.     PrintDefault( pPrintH );
  106.     
  107.     docWindow = FrontWindow();
  108.     if( docWindow != NIL_PTR )
  109.         MyDoDeactivateWindow( docWindow );
  110.  
  111.     dialog = GetNewDialog( HELP_DLOG, ALLOCATE_MEM, IN_FRONT );
  112.  
  113.     if( dialog == NIL_PTR )
  114.         return( result );
  115.  
  116.     /* AdjustMenus_(); */
  117.     SetUpHelpTEWindow( (WindowPtr)dialog, FALSE, TRUE, monaco, 9,
  118.         4, &te, &vScroll );
  119.     FnTE_GetTEXT( HELP_TEXT, &te, &vScroll );
  120.     
  121.     ShowWindow( dialog );
  122.     FnTE_UpdateWindow( (WindowPtr)dialog, &te, FALSE );
  123.     FnTE_FrameRect( (WindowPtr)dialog, &te, 4 );
  124.     FnMisc_FrameButton( dialog, OK_BUTTON );
  125.     
  126.     GetDItem( dialog, OK_BUTTON, &itemType, &itemHandle, &itemRect );
  127.     GetCTitle( (ControlHandle)itemHandle, okButtonStr );
  128.     GetDItem( dialog, PR_BUTTON, &itemType, &itemHandle, &itemRect );
  129.     GetCTitle( (ControlHandle)itemHandle, printButtonStr );
  130.     GetDItem( dialog, SV_BUTTON, &itemType, &itemHandle, &itemRect );
  131.     GetCTitle( (ControlHandle)itemHandle, saveButtonStr );
  132.     
  133.     done = FALSE;
  134.     while( done == FALSE )
  135.     {
  136.         ModalDialog( &MyHelpEventFilter, &itemHit );
  137.  
  138.         switch( itemHit )
  139.         {
  140.             case OK_BUTTON:
  141.                 result = TRUE;
  142.                 done = TRUE;
  143.                 break;
  144.             case PR_BUTTON:
  145.                 result = TRUE;
  146.                 FnIO_PrintTERecord( &te, &pPrintH );
  147.                 break;
  148.             case SV_BUTTON:
  149.                 result = TRUE;
  150.                 FnIO_SaveAsTextFile( &te,"\pHelp Text",&vRef,&refNum );
  151.                 break;
  152.             default:
  153.                 break;
  154.         }
  155.      }
  156.  
  157.     DisposeHandle( (Handle)te );
  158.     DisposeControl( vScroll );
  159.     DisposeHandle( (Handle)pPrintH );
  160.     DisposDialog( dialog );
  161.  
  162.     return( result );
  163. }
  164.  
  165.  
  166. /********** PASCAL MyHelpEventFilter */
  167.  
  168. pascal Boolean MyHelpEventFilter( DialogPtr    theDialog,
  169.                                   EventRecord  *theEvent,
  170.                                   short        *itemHit )
  171. {
  172.     short          thePart;
  173.     char           key;
  174.     short          itemType;
  175.     Handle         itemHandle;
  176.     Rect           itemRect;
  177.     long           finalTicks;
  178.     Rect           dragRect;
  179.     Boolean        result;
  180.     Point          theLocation;
  181.     WindowPtr      theWindow;
  182.     
  183.     result = FALSE;
  184.     dragRect = screenBits.bounds;
  185.     
  186.         switch( (*theEvent).what )
  187.         {
  188.             case mouseDown:
  189.                 thePart = FindWindow( (*theEvent).where, &theWindow );
  190.                 if( theWindow == theDialog )
  191.                 {
  192.                     switch( thePart )
  193.                     {
  194.                         case inDrag:
  195.                             DragWindow( theDialog,
  196.                                         (*theEvent).where,
  197.                                         &dragRect );
  198.                             result = TRUE;
  199.                             break;
  200.                         case inContent:
  201.                             if( theDialog == FrontWindow() )
  202.                             {
  203.                                 MyHelpDoContent( (WindowPtr)theDialog,
  204.                                     theEvent, &te, &vScroll, itemHit );
  205.                                 result = TRUE;
  206.                             }
  207.                             break;
  208.                         default:
  209.                             break;
  210.                      }
  211.                  }
  212.                 break;
  213.             case keyDown:
  214.             case autoKey:
  215.                 key = (*theEvent).message & charCodeMask;
  216.                 if( (key == RETURN_KEY) || (key == ENTER_KEY) )
  217.                 {
  218.                     GetDItem( theDialog,
  219.                               OK_BUTTON,
  220.                               &itemType,
  221.                               &itemHandle,
  222.                               &itemRect );
  223.                     HiliteControl( (ControlHandle)itemHandle,
  224.                                    inButton );
  225.                     Delay( VISUAL_DELAY, &finalTicks );
  226.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  227.                     *itemHit = OK_BUTTON;
  228.                     result = TRUE;
  229.                 }
  230.                 /* Handle other keyboard equivalents here */
  231.                 break;
  232.             case updateEvt:
  233.                 if( (WindowPtr)(*theEvent).message != theDialog )
  234.                 {
  235.                     MyDoUpdateWindow( (WindowPtr)(*theEvent).message );
  236.                 }
  237.                 else
  238.                 {
  239.                     FnTE_UpdateWindow( theDialog, &te, FALSE );
  240.                     FnTE_FrameRect( (WindowPtr)theDialog, &te, 4 );
  241.                     FnMisc_FrameButton( theDialog, OK_BUTTON );
  242.                 }
  243.                 break;
  244.             case activateEvt:
  245.                 if( (WindowPtr)(*theEvent).message != theDialog )
  246.                 {
  247.                     /*
  248.                     DoActivate_( (WindowPtr)(*theEvent).message,
  249.                                  ((*theEvent).modifiers & activeFlag),
  250.                                  *theEvent );
  251.                     */
  252.                  }
  253.                  break;
  254.             default:
  255.                  break;
  256.         }
  257.         
  258.     return( result );
  259. }
  260.  
  261. /********** SetUpHelpTEWindow */
  262.  
  263. Boolean SetUpHelpTEWindow(
  264.     WindowPtr  w,
  265.     Boolean    hasGrowIcon,
  266.     Boolean    wordWrap,
  267.     short      font,
  268.     short      textSize,
  269.     short      textInsetPixels,
  270.     // results //
  271.     TEHandle      *te,
  272.     ControlHandle *vScroll )
  273. /*
  274.     FnSetUpWindow takes information you supply about a window
  275.     and it's default text parameters then returns a TEHandle to
  276.     a text pane that fills the window and a ControlHandle to
  277.     a scroll bar that is located at the right of the window.
  278.     Returns FALSE if error detected during routine.
  279. */
  280. {
  281.     Rect       destRect, viewRect;
  282.     Rect       vSBarRect;
  283.     GrafPtr    oldPort;
  284.     int        SBarWidth = 15;
  285.     int        inset = 10;
  286.     int        bottomInset = 46;
  287.  
  288.     // define basic te stuff
  289.     GetPort( &oldPort );
  290.     SetPort( w );
  291.     TextFont( font );
  292.     TextSize( textSize ); 
  293.  
  294.     // set scroll bar rect       
  295.     vSBarRect = (*w).portRect;
  296.     vSBarRect.left = vSBarRect.right - SBarWidth - inset;
  297.     vSBarRect.right = vSBarRect.right + 1 - inset;
  298.     vSBarRect.top = vSBarRect.top - 1 + inset;
  299.     if( hasGrowIcon )
  300.         vSBarRect.bottom = vSBarRect.bottom - 14 - bottomInset;
  301.     else
  302.         vSBarRect.bottom = vSBarRect.bottom - bottomInset;
  303.     
  304.     // create new control      
  305.     *vScroll = NewControl( w, &vSBarRect, "\p", 1, 0, 0, 0,
  306.         scrollBarProc, 0L);
  307.     if( *vScroll == NULL )
  308.         return FALSE;
  309.     
  310.     // define te view and dest rects
  311.     viewRect = w->portRect;
  312.     viewRect.right = vSBarRect.left;
  313.     viewRect.bottom = vSBarRect.bottom;
  314.     viewRect.top = vSBarRect.top;
  315.     viewRect.left = viewRect.left + inset;
  316.     InsetRect(&viewRect, textInsetPixels, textInsetPixels);
  317.     destRect = viewRect;
  318.         
  319.     // create new te record
  320.     *te = TENew( &destRect, &viewRect );
  321.     if( *te == NULL )
  322.         return FALSE;
  323.     if( wordWrap )
  324.         (***te).crOnly = 1;
  325.     else
  326.         (***te).crOnly = -1;
  327.     
  328.     SetPort( oldPort );
  329.     return TRUE;
  330. }
  331.  
  332.  
  333. /********** MyHelpDoContent */
  334.  
  335. void MyHelpDoContent( WindowPtr     w, 
  336.                       EventRecord   *e,
  337.                       TEHandle      *te,
  338.                       ControlHandle *vScroll,
  339.                       short         *itemHit )
  340. /*
  341.     Use this procedure when user clicks in content region of TE window.
  342.     Uses the TnTE_ScrollProc below to take care of scroll bar function.
  343.     Also uses FnTE_AdjustText function.
  344. */
  345. {
  346.     int                cntlCode;
  347.     ControlHandle      cntl, compareCntl;
  348.     int                pageSize;
  349.     GrafPtr            savePort;
  350.     
  351.     GetPort(&savePort);
  352.     SetPort(w);
  353.     
  354.     *itemHit = 0;
  355.  
  356.     GlobalToLocal(&e->where);
  357.     if( (cntlCode = FindControl(e->where, w, &cntl)) == inButton )
  358.     {
  359.         if( TrackControl( cntl, e->where, 0L ) )
  360.         {
  361.             if(EqualString((**cntl).contrlTitle,okButtonStr,0,0))
  362.                 *itemHit = OK_BUTTON;
  363.             if(EqualString((**cntl).contrlTitle,printButtonStr,0,0))
  364.                 *itemHit = PR_BUTTON;            
  365.             if(EqualString((**cntl).contrlTitle,saveButtonStr,0,0))
  366.                 *itemHit = SV_BUTTON;            
  367.         }
  368.     }
  369.     else if( cntlCode == inThumb )
  370.     {
  371.         TrackControl( cntl, e->where, 0L );
  372.         FnTE_AdjustText( te, vScroll );
  373.     }
  374.     else if( (cntlCode == inUpButton) ||
  375.              (cntlCode == inDownButton) ||
  376.              (cntlCode == inPageUp) ||
  377.              (cntlCode == inPageDown) )
  378.     {
  379.         tempTEHptr = te;
  380.         tempVScrollptr = vScroll;
  381.         TrackControl( cntl, e->where, FnTE_ScrollProc );
  382.     }
  383.  
  384.     SetPort(savePort);
  385. }
  386.  
  387. // End of File